export default class NetSDK {


    private static _instance: NetSDK = null;
    public static getInstance(): NetSDK {
        if (!this._instance) {
            this._instance = new NetSDK();
        }
        return this._instance;
    }

    //
    private _net: XMLHttpRequest = null;

    private _callback: Function = null;

    constructor() {
        this._net = new XMLHttpRequest();
        this._net.onreadystatechange = () => {
            if (this._net.readyState == 4 && (this._net.status >= 200 && this._net.status < 400)) {
                const response = this._net.responseText;
                this._callback && this._callback(response);
                cc.log("收到的数据", response);
            }
        };

    }

    send(url, callback) {
        if (!this._net) return;

        this._callback = callback;
        this._net.open("GET", url, true);
        this._net.send();
    }

}